
************************************************************************
* Replication material for "The Social Dynamics of Collective Action:  *
* Evidence from the Diffusion of the Swing Riots, 1830-31"             *
*                                                                      *
* Aidt, Leon and Satchell (2020)                                       *
************************************************************************

*************************************************************************
* Requires the use of reg2hdfespatial. The code can be found here:      *
* http://www.trfetzer.com/wp-content/uploads/reg2hdfespatial-id1id2.ado *
*************************************************************************

clear
clear matrix
clear mata
set maxvar 32000

* Set directories to access ado files
sysdir set PERSONAL "C:\Users\k1466170\Documents\ado"
sysdir set PLUS "C:\Users\k1466170\Documents\ado"

* Load data
use Swing_data
set matsize 11000
set more off



* Define panel dimensions
encode par, gen (parN)
encode county, gen(countyN)

sort input_fid week_number

* Generate period vars (divide the 40 weeks into four periods of 10 weeks each)
gen period=.
replace period=1 if week_number<37
replace period=2 if week_number>36 & week_number<47
replace period=3 if week_number>46 & week_number<57
replace period=4 if week_number>56

gen par_period=period*100000+input_fid


* Generate dummies
gen totriotsD = 0
replace totriotsD=1 if totriots>0
replace totriotsD=. if totriots==.

gen L1totriotsD = 0
replace L1totriotsD=1 if L1totriots>0
replace L1totriotsD=. if L1totriots==.

gen riots_nearD=0
replace riots_nearD=1 if riots_near>0
replace riots_nearD=. if riots_near==.

gen L1riots_nearD=0
replace L1riots_nearD=1 if L1riots_near>0
replace L1riots_nearD=. if L1riots_near==.

* Check:
count if L1totriots==.
count if L1riots_near==.

* Set plotting scheme
set scheme plotplainblind



			****************************
			* Tables for the main text *
			****************************
			
**********************
* Table 1: Diffusion *
**********************



* Column 1
reg2hdfespatial totriots L1riots_near L1totriots, timevar(week_number) panelvar(input_fid) lat(latitude) lon(longitude) distcutoff(10) lagcutoff(40) disp
outreg2 using M1, tex(frag) auto(2) title(Main regressions) asterisk(se) ctitle(Riots) lab replace alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) drop(_I*) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, No, Standard errors, Conley, Estimation, OLS)

* Column 2 (parish-period trends)
reg2hdfespatial totriots L1riots_near L1totriots, timevar(week_number) panelvar(input_fid) altfepanel(par_period) lat(latitude) lon(longitude) distcutoff(10) lagcutoff(40) disp
outreg2 using M1, tex(frag) auto(2) ///
asterisk(se) ctitle(Riots) lab append alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) keep(L1* L2* L3*) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS)

* Column 3 (large riots only)
gen L1riots_large_near = l.riots_large_near
gen L1totriots_large = l.totriots_large
reg2hdfespatial totriots_large L1riots_large_near L1totriots_large,  lat(latitude) lon(longitude) timevar(week_number) panelvar(input_fid) altfepanel(par_period) dist(10) lag(40) disp
outreg2 using M1, tex(frag) auto(2) ///
asterisk(se) ctitle(Riots) lab append alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) keep(L*) sortvar(*riots_near *totriots) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS, Note, only large riots)

* Column 4 (small riots only) 
gen L1riots_small_near = l.riots_small_near
gen L1totriots_small = l.totriots_small
reg2hdfespatial totriots_small L1riots_small_near L1totriots_small,  lat(latitude) lon(longitude) timevar(week_number) panelvar(input_fid) altfepanel(par_period) dist(10) lag(40) disp
outreg2 using M1, tex(frag) auto(2) ///
asterisk(se) ctitle(Riots) lab append alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) keep(L*) sortvar(*riots_near *totriots) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS, Note, only small riots)

* Column 5 (onset)
* We use onset to deal with endogeneity, following the civil wars literature (and particularly Miguel, Satyanath and Sergenti)
* Measuring Onset: this is done by (i) redefining totriots so that it is a binary variable
* (called Briots), and (ii) by setting all Briots equal to missing after
* the first occurrence of a riot. This is equivalent to measuring 'onset'.

* The following bit of code creates a variable that equals 0 before the first
* riot has occurred, and 1 after that. I then use this variable to know when
* the first instace of a riot was, and set all future values equal to missing.
sort input_fid week_number
gen Briots=totriots
replace Briots=1 if totriots>1
gen first_riots=0
replace first_riot=1 if Briots==1
replace first_riot=1 if l.first_riot==1

* This is where I set all future totriots to missing.
replace Briots=. if first_riot==1 & l.first_riot==1
drop first_riot

reg2hdfespatial Briots L1riots_near, lat(latitude) lon(longitude) timevar(week_number) panelvar(input_fid) altfepanel(par_period) dist(10) lag(40) disp 
outreg2 using M1, tex(frag) auto(2) ///
asterisk(se) ctitle(Riots onset) lab append alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) keep(L*) sortvar(*riots_near *totriots) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS)


* Column 6 (three lags)
reg2hdfespatial totriots L1riots_near L2riots_near L3riots_near L1totriots L2totriots L3totriots, timevar(week_number) panelvar(input_fid) altfepanel(par_period) lat(latitude) lon(longitude) distcutoff(10) lagcutoff(40) disp
outreg2 using M1, tex(frag) auto(2) asterisk(se) ctitle(Riots) lab append alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) drop(_I*) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS)


* Column 7 (Poisson)
*** See R code


* Column 8 (MLE)
*** See R code



*************************************************
* Figure 3: interflex analysis for weekly riots *
*************************************************

* We do them with dummies to make things clearer

interflex totriots L1riots_nearD week_number L1totriots, n(10) fe(input_fid week_number) xlabel("weeks") ylabel("riots{sub:t-1}") dlabel("W x riots{sub:t-1}") vce(boot) xd(density)

interflex totriots L1riots_nearD week_number L1totriots, type(kernel) bw(5.7) fe(input_fid week_number) xlabel("weeks") ylabel("riots{sub:t-1}") dlabel("W x riots{sub:t-1}") vce(boot) xd(density)



**************************************************
* Figure 4 (and online appendix table A8): Fairs *
**************************************************



lab variable L1riots_near "W x riots{sub:t-1}"

sort input_fid week_number
* generate the dummies
gen fairsB=0
replace fairsB=1 if total_fairs>0
gen LfairsB=l.fairsB

lab variable LfairsB "d(fairsN{sub:t-1})"


* The following includes all riots near fair locations (only when fair is running)
gen riots_fairsB=0
replace riots_fairsB=1 if riots_fairs>0
gen Lriots_fairsB=l.riots_fairsB
lab variable Lriots_fairsB "d(riots near fair that is running (t-1)) (bin)"

* The following includes all riots near fair locations (even if the fair isn't running)
gen riots_fairs_allB=0
replace riots_fairs_allB=1 if riots_market_town>0
gen Lriots_fairs_allB=l.riots_fairs_allB
lab variable Lriots_fairs_allB "d(riots near fair{sub:t-1})"

* This interaction only includes riots in the week the fair is on.
gen LfairsBInt=LfairsB*Lriots_fairsB
lab variable LfairsBInt "D(fairsN{sub:t-1}) x d(riots near fair{sub:t-1})"





* Column 1
reg2hdfespatial totriots L1totriots L1riots_near LfairsB, lat(latitude) lon(longitude) timevar(week_number) panelvar(input_fid) altfepanel(par_period) dist(10) lag(40) disp 
estimates store fairs1
outreg2 using A8, tex(frag) auto(2) title(Estimation using Fairs) ///
asterisk(se) ctitle(Riots) lab replace alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) sortvar(*riots_near *totriots) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS)


* Find parishes with fairs (to check variation) - most of them were near a fair.
sort input_fid week_number
by input_fid: egen sum_all_fairs=total(total_fairs)
gen par_with_fair=0
replace par_with_fair=1 if sum_all_fairs>0
* Here are the counts, to get a parish count we need to divide by 40 because each parish appears 40 times
* But can get the correct ration just by dividing.
count if par_with_fair==0
count if par_with_fair==1


* Column 2

* The interaction is not done directly, for the reason I now outline. A parish may be near several fair locations, and they won't
* be on at the same time. So constructing an interaction in the traditional way would be impossible. This is because we have one observation
* per parish-week. So, for example, consider the following situation:
* (time t)	fairs near i   riots near fair
* parish i    fair 1 on        0
* parish i    fair 2 on        0
* parish i    fair 3 off       1
*
* If we want to include riots near fairs in cases where the fair is off (because this is interesting, but also because otherwise the interaction brings
* no additional variation), we can't just multiply a dummy for fairs near and a dummy for riots near fairs. Because if we do, the above example is likely
* to generate a 1, when in reality there are no riots near the fairs. And that is why we construct the interaction by hand: LfairsBInt is constructed
* from only riots near parishes where fairs are taking place. That means that in the above example we get a zero. But we get a 1 for e.g. cases like the
* following:
* (time t)	  fairs near i   riots near fair
* parish i    fair 1 on        1
* parish i    fair 2 on        0
* parish i    fair 3 off       1


reg2hdfespatial totriots L1riots_near L1totriots LfairsB LfairsBInt Lriots_fairs_allB, lat(latitude) lon(longitude) timevar(week_number) panelvar(input_fid) altfepanel(par_period) dist(10) lag(40) disp 
estimates store fairs2
outreg2 using A8, tex(frag) auto(2) ///
asterisk(se) ctitle(Riots) lab append alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) sortvar(*riots_near *totriots) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS)


* Produce cross-tabulations to see whether we have enough variation
tab Lriots_fairs_allB LfairsB 


#delimit ;
coefplot
(fairs1), bylabel(column 1) ||
(fairs2), bylabel(column 2) ||,
drop(L1totriots)  omitted  xline(0, lcolor(black) lwidth(thin))
;





******************************************************************************
* Figure 5 (and table A9 in the online appendix): Coach stops and newspapers *
******************************************************************************


lab variable L1totriotsD "d(riots{sub:t-1})"
lab variable L1riots_nearD "d(W x riots{sub:t-1})"



* Column 1 (coach stops) *
* We run a regression on dummies (following the Hainmueller et al.)

gen IcoachD = coach_10 *L1riots_nearD
lab variable IcoachD "D(coachstopN) x d(W x riots{sub:t-1})"

reg2hdfespatial totriots L1totriotsD coach_10 L1riots_nearD IcoachD, lat(latitude) lon(longitude) timevar(week_number) panelvar(input_fid) altfepanel(par_period) dist(10) lag(40) disp
estimates store coach
outreg2 using A9, tex(frag) auto(2) title(Estimation using Coach stops and Newspapers) ///
asterisk(se) ctitle(Riots) lab append alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) sortvar(*riots_near *totriots) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS)


* Column 2: newspapers *
* We run a regression on dummies (following the Hainmueller et al.)

gen InewsD = news_10 *L1riots_nearD
lab variable InewsD "D(newspaperN) x d(W x riots{sub:t-1})"

reg2hdfespatial totriots L1totriotsD news_10 L1riots_nearD InewsD, lat(latitude) lon(longitude) timevar(week_number) panelvar(input_fid) altfepanel(par_period) dist(10) lag(40) disp
estimates store news
outreg2 using A9, tex(frag) auto(2)  ///
asterisk(se) ctitle(Riots) lab replace alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) sortvar(*riots_near *totriots) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS)



* Produce cross-tabulations to check that we have enough variation
tab L1riots_nearD coach_10
tab L1riots_nearD news_10


* New figure that combines them both
#delimit ;
coefplot
(coach), bylabel(Coach stops) ||
(news), bylabel(Newspapers) ||,
drop(L1totriotsD) omitted xline(0, lcolor(black) lwidth(thin))
;



**************************************************************************************
* Figure 6 (and tables A10 and A11 in the online appendix): Repression and Petitions *
**************************************************************************************

* Repression
* Note that there can be no repression in the absence of riots, and so either the dummy
* or the interaction are dropped (see the paper for more details).

gen L1riotsB_near_r=l.riotsB_near_r
lab var L1riotsB_near_r "neighboring riots that were repressed, binary (t-1)"

gen L1riotsB_r=l.riotsB_r
lab var L1riotsB_r "riots that were repressed, binary (t-1)"

* Generate interactions
* The variable for repression in own parish is L1riotsB_r. Rename it:
gen repress_own=riotsB_r
gen Lrepress_own=L1riotsB_r
label var Lrepress_own "repression{sub:t-1} (bin)"
* The variable for repression in nearby parishes is L1riotsB_near_r
gen repress_near=riotsB_near_r
gen Lrepress_near=L1riotsB_near_r
label var Lrepress_near "repression nearby{sub:t-1} (bin)"

* The variables that are dropped change, but the results are the same. So we always label them as the interaction
gen Int_own_rep = L1totriotsD * Lrepress_own
label var Int_own_rep "riots{sub:t-1} (bin) x repression{sub:t-1} (bin)"
label var Lrepress_own "riots{sub:t-1} (bin) x repression{sub:t-1} (bin)"

gen Int_neigh_rep = L1riots_nearD * Lrepress_near
label var Int_neigh_rep "riots nearby{sub:t-1} (bin) x repression nearby{sub:t-1} (bin)"
label var Lrepress_near "riots nearby{sub:t-1} (bin) x repression nearby{sub:t-1} (bin)"

reg2hdfespatial totriots L1totriotsD Lrepress_own Int_own_rep L1riots_nearD Lrepress_near Int_neigh_rep, timevar(week_number) panelvar(input_fid) altfepanel(par_period) lat(latitude) lon(longitude) distcutoff(10) lagcutoff(40) disp
estimates store repression
outreg2 using A10, tex(frag) auto(2) title(Repression) asterisk(se) ctitle(Riots) lab replace alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) drop(_I*) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS)

* Test whether the coefficients are equal
test L1totriotsD = Lrepress_own
test L1riots_nearD = Lrepress_near


* Label the variables
label variable L1totriotsD "d(riots{sub:t-1})"

* One of each variable in the following two pairs gets dropped; we label both the same to ensure the
* figure produced always has the same labels
label variable Lrepress_own "D(repression{sub:t-1}) x d(riots{sub:t-1})"
label variable Int_own_rep "D(repression{sub:t-1}) x d(riots{sub:t-1})"

label variable Lrepress_near "D(repression nearby{sub:t-1}) x d(W x riots{sub:t-1})"
label variable Int_neigh_rep "D(repression nearby{sub:t-1}) x d(W x riots{sub:t-1})"

* Cross-tabulations to check that that there is enough variation
tab L1totriotsD Lrepress_own
tab L1riots_nearD Lrepress_near


#delimit ;
coefplot
(repression) ||,
omitted xline(0, lcolor(black) lwidth(thin)) 
;





* PETITIONS *

gen petitionsB=0
replace petitionsB=1 if ln_petitions>0

* Find parishes with petitions
sort input_fid week_number
by input_fid: egen sum_all_petitions=total(ln_petitions)
gen par_with_petition=0
replace par_with_petition=1 if sum_all_petitions>0

* Here are the counts, to get a parish count we need to divide by 40 because each parish appears 40 times
* But can get the correct ratio just by dividing.
count if par_with_petition==0
count if par_with_petition==1


* We run the regression on dummies (following the Hainmueller et al.)
gen IpetitionsD = par_with_petition * L1riots_nearD

label variable L1riots_nearD "d(W x riots{sub:t-1})"
label var IpetitionsD "D(petitionsN) x d(W x riots{sub:t-1})"


reg2hdfespatial totriots L1totriotsD L1riots_nearD par_with_petition IpetitionsD, lat(latitude) lon(longitude) timevar(week_number) panelvar(input_fid) altfepanel(par_period) dist(10) lag(40) disp
estimates store petitions
outreg2 using A11, tex(frag) auto(2) title(Petitions) ///
asterisk(se) ctitle(Riots) lab replace alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) sortvar(*riots_near *totriots) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS)



* Cross-tabulations to check that we have enough variation
tab L1riots_nearD par_with_petition

#delimit ;
coefplot
(petitions) ||,
drop(L1totriotsD) omitted xline(0, lcolor(black) lwidth(thin)) byopts(xrescale) xscale(r(0 0.05)) xlabel(0 "0" .01 ".01" .02 ".02" 0.03 "0.03" 0.04 "0.04" 0.05 "0.05")
;


							    ************
							    * APPENDIX *
							    ************

							
***************************
* Table 2: summary stats *
***************************
sum totriots riots_near totriotsD riots_nearD fairsB riots_fairs_allB news_10 coach_10 repress_own repress_near petitionsB





							*******************
							* ONLINE APPENDIX *
							*******************


******************************************************
* Figure A1: distribution of distances to newspapers *
******************************************************
*** See the other .do files


*********************************
* Table A2: correlations matrix *
*********************************
gen cereal = 0
replace cereal=1 if agtype2==1 | agtype4==1

corrtex market_10 coach_10 news_10 ln_petitions riotsB_r cereal ln_rural ln_total_of_person ln_males enclosure ln_trade ln_professionals ln_garr_min_dis Dpolice1 DLondon20, file(corr.tex)


*************************************************************
* Figure A2: Total cumulative impact of an additional riots *
*************************************************************
*** See R code


****************************************
* Table A3: estimates using daily data *
****************************************
*** See the other .do files


*******************************************
* Table A4: Robustness to row-normalizing *
*******************************************

reg2hdfespatial totriots L1riots_near_RN L1totriots, timevar(week_number) panelvar(input_fid) lat(latitude) lon(longitude) distcutoff(10) lagcutoff(40) disp
outreg2 using A4, tex(frag) auto(2) title(Row normalised) asterisk(se) ctitle(Riots) lab replace alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) drop(_I*) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, No, Standard errors, Conley, Estimation, OLS)

reg2hdfespatial totriots L1riots_near_RN L1totriots, timevar(week_number) panelvar(input_fid) altfepanel(par_period) lat(latitude) lon(longitude) distcutoff(10) lagcutoff(40) disp
outreg2 using A4, tex(frag) auto(2) ///
asterisk(se) ctitle(Riots) lab append alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) keep(L1* L2* L3*) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS)

reg2hdfespatial totriots L1riots_near_RN L2riots_near_RN L3riots_near_RN L1totriots L2totriots L3totriots, timevar(week_number) panelvar(input_fid) altfepanel(par_period) lat(latitude) lon(longitude) distcutoff(10) lagcutoff(40) disp
outreg2 using A4, tex(frag) auto(2) asterisk(se) ctitle(Riots) lab append alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) drop(_I*) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS)


***********************************************
* Table A5: Robustness to including more lags *
***********************************************


reg2hdfespatial totriots L1riots_near L1totriots, timevar(week_number) panelvar(input_fid) altfepanel(par_period) lat(latitude) lon(longitude) distcutoff(10) lagcutoff(40) disp
outreg2 using A5, tex(frag) auto(2) title (Additional lags) asterisk(se) ctitle(Riots) lab replace alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) drop(_I*) addtext(Fixed effect, Parish, Week FE, YES, Time trend, parish x period, Standard errors, Conley)

reg2hdfespatial totriots L1riots_near L2riots_near L1totriots L2totriots, timevar(week_number) panelvar(input_fid) altfepanel(par_period) lat(latitude) lon(longitude) distcutoff(10) lagcutoff(40) disp
outreg2 using A5, tex(frag) auto(2) asterisk(se) ctitle(Riots) lab append alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) drop(_I*) addtext(Fixed effect, Parish, Week FE, YES, Time trend, parish x period, Standard errors, Conley)

reg2hdfespatial totriots L1riots_near L2riots_near L3riots_near L1totriots L2totriots L3totriots, timevar(week_number) panelvar(input_fid) altfepanel(par_period) lat(latitude) lon(longitude) distcutoff(10) lagcutoff(40) disp
outreg2 using A5, tex(frag) auto(2) asterisk(se) ctitle(Riots) lab append alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) drop(_I*) addtext(Fixed effect, Parish, Week FE, YES, Time trend, parish x period, Standard errors, Conley)

reg2hdfespatial totriots L1riots_near L2riots_near L3riots_near L4riots_near L1totriots L2totriots L3totriots L4totriots, timevar(week_number) panelvar(input_fid) altfepanel(par_period) lat(latitude) lon(longitude) distcutoff(10) lagcutoff(40) disp
outreg2 using A5, tex(frag) auto(2) asterisk(se) ctitle(Riots) lab append alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) drop(_I*) addtext(Fixed effect, Parish, Week FE, YES, Time trend, parish x period, Standard errors, Conley)

reg2hdfespatial totriots L1riots_near L2riots_near L3riots_near L4riots_near L5riots_near L6riots_near L7riots_near L8riots_near L9riots_near L10riots_near L1totriots L2totriots L3totriots L4totriots L5totriots L6totriots L7totriots L8totriots L9totriots L10totriots, timevar(week_number) panelvar(input_fid) altfepanel(par_period) lat(latitude) lon(longitude) distcutoff(10) lagcutoff(40) disp
outreg2 using A5, tex(frag) auto(2) asterisk(se) ctitle(Riots) lab append alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) drop(_I*) addtext(Fixed effect, Parish, Week FE, YES, Time trend, parish x period, Standard errors, Conley)


*************************************************************
* Table A6: Robustness to dropping Kent and dropping London *
*************************************************************

* Column 1: no Kent
reg2hdfespatial totriots L1riots_near L1totriots if county!="KENT",  lat(latitude) lon(longitude) timevar(week_number) panelvar(input_fid) altfepanel(par_period) dist(10) lag(40) disp
outreg2 using A6, tex(frag) auto(2) title(Robustness) ///
asterisk(se) ctitle(Riots) lab replace alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) keep(L*) sortvar(*riots_near *totriots) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS, Note, No Kent)

* Column 2: no London
reg2hdfespatial totriots L1riots_near L1totriots if DLondon20!=1,  lat(latitude) lon(longitude) timevar(week_number) panelvar(input_fid) altfepanel(par_period) dist(10) lag(40) disp
outreg2 using A6, tex(frag) auto(2) ///
asterisk(se) ctitle(Riots) lab append alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) keep(L*) sortvar(*riots_near *totriots) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS, Note, excl < 20km London)


********************************
* Table A7: 20km neighborhoods *
********************************


gen L1riots_near20 = l.riots_near20
gen L2riots_near20 = ll.riots_near20
gen L3riots_near20 = lll.riots_near20

reg2hdfespatial totriots L1riots_near20 L1totriots, timevar(week_number) panelvar(input_fid) lat(latitude) lon(longitude) distcutoff(10) lagcutoff(40) disp
outreg2 using A7, tex(frag) auto(2) title(20km neighborhoods) asterisk(se) ctitle(Riots) lab replace alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) drop(_I*) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, No, Standard errors, Conley, Estimation, OLS)

reg2hdfespatial totriots L1riots_near20 L1totriots, timevar(week_number) panelvar(input_fid) altfepanel(par_period) lat(latitude) lon(longitude) distcutoff(10) lagcutoff(40) disp
outreg2 using A7, tex(frag) auto(2) asterisk(se) ctitle(Riots) lab append alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) drop(_I*) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS)

reg2hdfespatial totriots L1riots_near20 L2riots_near20 L3riots_near20 L1totriots L2totriots L3totriots, timevar(week_number) panelvar(input_fid) lat(latitude) lon(longitude) distcutoff(10) lagcutoff(40) disp
outreg2 using A7, tex(frag) auto(2) asterisk(se) ctitle(Riots) lab append alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) drop(_I*) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS)


*******************
* Table A8: Fairs *
*******************
*** Generated earlier in this file


****************************************
* Table A9: Coach stops and newspapers *
****************************************
*** Generated earlier in this file


*************************
* Table A10: Repression *
*************************
*** Generated earlier in this file


************************
* Table A11: Petitions *
************************
*** Generated earlier in this file


*******************************************
* Table A12: Fairs (large incidents only) *
*******************************************

gen L1totriots_large=l.totriots_large

* Create a binary variable of riots nearby
gen L1riots_large_near=l.riots_large_near

* Use the binary version of riots for the interactions
gen L1riots_large_nearD=0
replace L1riots_large_nearD=1 if L1riots_large_near>0 & L1riots_large_near!=.

* Use the binary version of riots for the interactions
gen LfairsBIntD_large=LfairsB*Lriots_fairsB
lab variable LfairsBIntD_large "Fairs (10km) (bin) (t-1) x Riots neighborhood (large) (t-1)"


reg2hdfespatial totriots_large L1riots_large_near L1totriots_large LfairsB, lat(latitude) lon(longitude) timevar(week_number) panelvar(input_fid) altfepanel(par_period) dist(10) lag(40) disp 
outreg2 using A12, tex(frag) auto(2) title(Fairs - large riots) ///
asterisk(se) ctitle(Riots) lab replace alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) sortvar(*riots_near *totriots) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS)

reg2hdfespatial totriots_large L1riots_large_near L1totriots_large LfairsB LfairsBIntD_large Lriots_fairs_allB, lat(latitude) lon(longitude) timevar(week_number) panelvar(input_fid) altfepanel(par_period) dist(10) lag(40) disp 
outreg2 using A12, tex(frag) auto(2) ///
asterisk(se) ctitle(Riots) lab append alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) sortvar(*riots_near *totriots) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS)


****************************************************************
* Table A13: Coach stops and newspapers (large incidents only) *
***************************************************************

gen Inews_10_large_nearD=news_10*L1riots_large_nearD
label var Inews_10_large_nearD "Newspaper (10km) (bin) x Riots neighborhood (large) (t-1)"

gen Icoach_10_large_nearD=coach_10*L1riots_large_nearD
label var Icoach_10_large_nearD "Coach stop (10km) (bin) x Riots neighborhood (large) (t-1)"



* COACHES *
reg2hdfespatial totriots_large L1totriots_large L1riots_large_nearD Icoach_10_large_nearD coach_10, lat(latitude) lon(longitude) timevar(week_number) panelvar(input_fid) altfepanel(par_period) dist(10) lag(40) disp
outreg2 using A13, tex(frag) auto(2) title(Coach stops and Newspapers - large) ///
asterisk(se) ctitle(Riots) lab replace alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) sortvar(*riots_near *totriots) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS)


* NEWSPAPERS *
reg2hdfespatial totriots_large L1totriots_large L1riots_large_nearD Inews_10_large_nearD news_10, lat(latitude) lon(longitude) timevar(week_number) panelvar(input_fid) altfepanel(par_period) dist(10) lag(40) disp
outreg2 using A13, tex(frag) auto(2) title(M4: Estimation using Newspapers, Coach Stops and Petitions) ///
asterisk(se) ctitle(Riots) lab append alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**,*,+) sortvar(*riots_near *totriots) addtext(Fixed effect, Parish, Time dummies, Weeks, Time trend, parish x period, Standard errors, Conley, Estimation, OLS)



